<template>
  <van-loading v-if="loading" size="0.5rem" />
  <van-icon
    v-else
    :color="value ? '#ffa500' : `#777`"
    :name="value ? 'star' : 'star-o'"
    @click="onCollect"
  />
</template>

<script>
import { addCollect, deleteCollect } from "@/api/article";
export default {
  name: "CollectArticle",
  props: {
    value: {
      type: Boolean,
      required: true,
    },
    id: {
      type: [String, Number],
      required: true,
    },
  },
  data() {
    return {
      loading: false,
    };
  },
  methods: {
    async onCollect() {
      this.loading = true;
      // console.log(this.id);
      if (this.value) {
        await deleteCollect(this.id);
      } else {
        await addCollect(this.id);
      }
      this.$emit("input", !this.value);
      this.loading = false;
    },
  },
};
</script>

<style>
</style>